/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import Entities.Actor;
import Entities.Artist;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

/**
 *
 * @author sebastian
 */
public class ArtistController {
           EntityManagerFactory emf = Persistence.createEntityManagerFactory("GRLU");
     
  public List<Artist> getArtistbyName(String artistName){
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        TypedQuery<Artist> query = (TypedQuery<Artist>) em.createNamedQuery("Artist.findByName", Artist.class);
        query.setParameter("name", artistName);
        List<Artist> resultsArtists = query.getResultList();        
        return resultsArtists;
    }
    
   public Artist getSingleArtist(String nameArtist){
   
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        TypedQuery query = (TypedQuery) em.createNamedQuery("Artist.findByName", Artist.class);
        query.setParameter("name", nameArtist);
        Artist results = (Artist)query.getSingleResult();
        
        return results;                
    }
  
}
